// 商品分类全局组件数据
import { defineStore } from 'pinia'
import { reqC1, reqC2, reqC3 } from '@/api/product/attr'
import type { CategoryResponseData } from '@/api/product/attr/type'
import type { CategoryState } from './type/type'
const useCategoryStore = defineStore('CategoryStore', {
    state: (): CategoryState => {
        return {
            c1Arr: [], //c1数组
            c1Id: '',  // c1的id
            c2Arr: [], //c2数组
            c2Id: '', // c2的id
            c3Arr: [], //c3数组
            c3Id: '', // c3的id
        }
    },
    actions: {
        async getC1() {
            let result: CategoryResponseData = await reqC1()
            if (result.code == 200) {
                this.c1Arr = result.data
            }
        },
        async getC2() {
            let result: CategoryResponseData = await reqC2(this.c1Id)
            if (result.code == 200) {
                this.c2Arr = result.data
            }
        },
        async getC3() {
            let result: CategoryResponseData = await reqC3(this.c2Id)
            if (result.code == 200) {
                this.c3Arr = result.data
            }
        }
    },
    getters: {

    }
})

export default useCategoryStore
